import dotenv
import weaviate
from langchain_openai import OpenAIEmbeddings
from langchain_weaviate import WeaviateVectorStore
from weaviate.auth import AuthApiKey
from weaviate.collections.classes.filters import Filter

dotenv.load_dotenv()

client = weaviate.connect_to_weaviate_cloud(
    cluster_url="https://ch1cjmeqwksbbi0taqj4g.c0.asia-southeast1.gcp.weaviate.cloud",
    auth_credentials=AuthApiKey("bjg3NHRXdlJ3K0xvT2d1UV9xdzVEbG9SQ3p2NUR6S0EvSWhtS1JtV09laFpOQTdadzFSTmFuakJxUlJJPV92MjAw")
)
embedding = OpenAIEmbeddings(model="text-embedding-3-small")
db = WeaviateVectorStore(client= client, index_name="DataSetText", text_key="text", embedding=embedding)


#ids = db.add_texts(texts=texts,metadatas=metadatas)
#print(ids)
# 带过滤性的相似性搜索
filters = Filter.by_property("page").greater_than(5)
search_results = db.similarity_search_with_score("请问有一只猫叫笨笨吗？", filters= filters)
for  one in search_results:
    print(one)
client.close()